﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

using MpSoft.Library.BUSS.Categories;
using MpSoft.Library.DTO;

namespace MpSoft.Web.AdminCP.Controls.Category
{
    public partial class MenuManage : System.Web.UI.UserControl
    {
        #region Var
        #endregion

        #region Method

        protected string GetMenu()
        {
            StringBuilder sb = new StringBuilder(3232);
            var listMenu = MenuBUSS.Menu_List();
            foreach (var obj in listMenu)
            {
                sb.Append("<div class='check-line'>");
                sb.Append("<input type='radio' id='" + obj.MenuCode + "' value='" + obj.MenuCode + "' class='icheck-me' name='rdmenu' data-skin='square' data-color='blue'>");
                sb.Append("<label class='inline' for='" + obj.MenuCode + "'>" + obj.MenuTitle + "</label>");
                sb.Append("</div>");
            }
            return sb.ToString();
        }

        protected string Categories()
        {
            var listCate = CategoryBUSS.Category_ByParentID(0, null, null, 0);
            if (listCate != null)
                return SubCategories("class='folder'", listCate);
            return "";
        }

        private string SubCategories(string cssfolder,List<Library.DTO.Category> listCate)
        {
            StringBuilder sb = new StringBuilder();
            if (listCate.Count > 0)
            {
                sb.Append("<ul>");
                foreach (var obj in listCate)
                {
                    sb.Append("<li " + cssfolder + " id='" + obj.CategoryID + "' data=\"addClass: '" + obj.MenuID.Replace(",", " ") + "'\">" + obj.CategoryName);
                    var sub_categories = CategoryBUSS.Category_ByParentID(obj.CategoryID, null, null, 0);
                    if (sub_categories != null)
                        sb.Append(SubCategories("class='folder'", sub_categories));
                    sb.Append("</li>");
                }
                sb.Append("</ul>");
            }
            return sb.ToString();
        }

        #endregion

        #region Event

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #endregion

        #region Properties
        #endregion
    }
}